package DAO;

import java.util.List;

import interfacedao.AtendenteDAO;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import modelo.Atendente;

/**
 * Session Bean implementation class AtendenteDAOBean
 */
@Stateless
@LocalBean
public class AtendenteDAOBean implements AtendenteDAO {

	@PersistenceContext(unitName="prova")
	private EntityManager em;
	
    public AtendenteDAOBean() {
        
    }

	@Override
	public Atendente recuperarLogin(String login, String senha) {
		return em.createNamedQuery("logarAtendente", Atendente.class)
				.setParameter("login", login).setParameter("senha", senha)
				.getSingleResult();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Atendente> buscaAtendentes() {
		Query query = em.createNamedQuery("listaAtentendes", Atendente.class);
		return query.getResultList();
	}

	@Override
	public void criarAtendente(Atendente a) {
		em.persist(a);
		
	}

	@Override
	public boolean apagarAtendente(Atendente a) {
		try {
			em.remove(a);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	@Override
	public void atualizaAtendente(Atendente a) {
		em.merge(a);
		
	}

}
